﻿#ifndef __CLIST_H__
#define __CLIST_H__

#ifdef __cplusplus
extern "C" {
#endif

#define NODE_DATA_PTR(node_ptr) ((char*)node_ptr + sizeof(void*) * 2) //sizeof(void*) -> sizeof(CLIST_NODE)
#define IT_PTR(it, usr_type) ((usr_type*)NODE_DATA_PTR(it.ptr))

typedef struct _clist_itorator {
	//attribute
	void* ptr;

	//action
	void* (*next)(struct _clist_itorator* thes);
} CListIterator;

typedef struct _clist_ {
	//attribute
	void* ptr;
	int item_size;
	int cnt;

	//action
	int(*insert)(struct _clist_* thes, void* e);
	int(*erase)(struct _clist_* thes, CListIterator* it);
	void*(*begin)(struct _clist_* thes);
	void*(*end)(struct _clist_* thes);
	int(*release)(struct _clist_* thes);
} CList;

int construct_clist(CList* thes, int item_size);
int construct_clist_iterator(CListIterator* thes);

#ifdef __cplusplus
}
#endif
#endif
